package com.mdh.runerrands.serviceImpl;

import com.mdh.runerrands.dao.BaseUserDao;
import com.mdh.runerrands.pojo.BaseUser;
import com.mdh.runerrands.service.BaseUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class BaseUserServiceImpl implements BaseUserService {
    @Resource
    private BaseUserDao baseUserDao;

    @Override
    public List<BaseUser> findBaseUserAll() {
        List<BaseUser> baseUsers = baseUserDao.selectAll();
        return baseUsers;
    }

    @Override
    public int deleteBaseUserById(int id) {
        return baseUserDao.deleteById(id);
    }

    @Override
    public int insert(BaseUser baseUser) {
        return baseUserDao.insert(baseUser);
    }

    @Override
    public BaseUser findBaseUserById(int id) {
        return baseUserDao.selectById(id);
    }

    @Override
    public int update(BaseUser baseUser) {
        return baseUserDao.update(baseUser);
    }

    @Override
    public boolean batchDelete(int... ids) {
        return baseUserDao.batchDelete(ids);
    }

    @Override
    public List<BaseUser> query(int page, int pageSize, String telephone, String realname, String idCard, String status) {
        page = (page -1)*pageSize;
        String type = "waiter";
        return baseUserDao.selectQuery(page,pageSize,telephone,realname,idCard,status,type);
    }

    @Override
    public int waiterCount(String telephone, String realname, String idCard, String status) {
        String type = "waiter";
        return baseUserDao.selectCountWaiter(telephone,realname,idCard,status,type);
    }

    @Override
    public List<BaseUser> customerQuery(int page, int pageSize, String realName, String telephone, String status) {
        page = (page -1)*pageSize;
        String type = "customer";
        return baseUserDao.selectCustomerQuery(page,pageSize,realName,telephone,status,type);
    }

    @Override
    public int customerCount(String realName, String telephone, String status) {
        String type = "customer";
        int i = baseUserDao.selectCountCustomer(realName, telephone, status, type);
        return i;

    }

    @Override
    public boolean recharge(int id, String money) {
        return baseUserDao.updateCustomerMoney(id,money);
    }

    @Override
    public BaseUser findByUsername(String username) {
        return baseUserDao.selectByUserName(username);
    }
}
